#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode* ret = new ListNode(0, head);
        ListNode* prev = ret;
        ListNode* cur = head;
        ListNode* next = head->next;
        while (next)
        {
            while (next && cur->val == next->val)
                next = next->next;
            if (cur->next != next)
            {
                prev->next = next;
                while (cur == next)
                {
                    ListNode* tmp = cur;
                    cur = cur->next;
                    delete tmp;
                }
            }
            else
                prev = cur;
            cur = next;
            if (cur == nullptr || cur->next == nullptr)
                break;
            next = cur->next;
        }
        head = ret->next;
        delete ret;
        return head;
    }
};

class Solution {
public:
    void _delDupR(ListNode*& head, ListNode* prev, ListNode* cur, int& target)
    {
        if (cur == nullptr)
            return;
        _delDupR(head, cur, cur->next, target);
        if (prev == nullptr)
        {
            if (target == 1)
            {
                head = cur->next;
                delete cur;
            }
            return;
        }
        if (target == 1 || prev->val == cur->val)
        {
            target = 1;
            ListNode* tmp = cur;
            prev->next = cur->next;
            cur = cur->next;
            if (prev->val != tmp->val)
                target = 0;
            delete tmp;
        }
    }

    ListNode* deleteDuplicates(ListNode* head) {
        if (head == nullptr || head->next == nullptr)
            return head;
        int target = 0;
        _delDupR(head, nullptr, head, target);
        return head;
    }
};

class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        if (head == nullptr || head->next == nullptr || head->next->next == nullptr)
            return head;
        ListNode* head1 = head;
        ListNode* prev1 = head;
        ListNode* cur1 = head;
        ListNode* head2 = head->next;
        ListNode* prev2 = head2;
        ListNode* cur2 = head2;
        while (cur1->next && cur1->next->next)
        {
            cur1 = prev2->next;
            if (cur1->next == nullptr)
                cur2 = nullptr;
            else
                cur2 = cur1->next;
            prev1->next = cur1;
            prev1 = prev1->next;
            prev2->next = cur2;
            prev2 = prev2->next;
        }
        cur1->next = head2;
        return head;
    }
};//